package com.example.wmstore.controller;


import com.example.wmstore.common.Result;
import com.example.wmstore.entity.Menu;
import com.example.wmstore.entity.User;
import com.example.wmstore.service.MenuService;
import com.example.wmstore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author TCW
 * @since 2024-05-29
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<Menu> list() {
        return menuService.list();
    }
    @GetMapping("/{role}")
    public Result rolemenu(@PathVariable Integer role){
        List list = menuService.lambdaQuery().like(Menu::getMenuright,role).list();
        return Result.suc(list);
    }
    @GetMapping("/{id}")
    public Result usermenu(@PathVariable Integer id){
        List list=menuService.lambdaQuery().like(Menu::getMenuright,userService.getById(id).getRole()).list();
        return Result.suc(list);
    }

}
